from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from meiduo_admin.serializers.admin_user import AdminSerializer
from meiduo_admin.serializers.groups import GroupSerializer
from meiduo_admin.utils import PageNum
from django.contrib.auth.models import Group

from users.models import User


class AdminUserView(ModelViewSet):

    """
        管理员的增删改查
    """
    # 指定序列化器
    serializer_class = AdminSerializer
    # 指定查询集
    queryset = User.objects.filter(is_staff=True)
    # 指定分页器
    pagination_class = PageNum
    # 指定权限
    permission_classes = [IsAdminUser]


    # 获取所有分组表信息
    def simple(self,reqeust):
        # 1、获取所有分组对象
        groups=Group.objects.all()
        # 2、返回分组信息
        ser=GroupSerializer(groups,many=True)
        return Response(ser.data)
